<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of PPS
 *
 * @author sunday 2014.05.26 add  modify by dragon.hu @ 2016.3.21
 */
require_once 'BaseChannel.php';

//PPS
class Pps implements BaseChannel {

    //put your code here
    function __construct() {
        
    }

    function android($data) {
        $appkey = "51d88555123bea033c113bd220ab4af9";  //充值key
        echo $this->payCallBackMethod($appkey, ANDROID);
    }

    function ios($data) {
        
    }

    public function payCallBackMethod($appkey, $platform) {

        $orderLog = new ChargeOrder();
        $orderLog->log("pps", $_REQUEST);

        $user_id = $_REQUEST['user_id'];
        $order_id = $_REQUEST['order_id'];
        $role_id = $_REQUEST['role_id'];
        $time = $_REQUEST['time'];
        $money = $_REQUEST['money'];
        $sign = $_REQUEST['sign'];
		$userData=$_REQUEST['userData'];

        $sign_check = md5($user_id . $role_id . $order_id . $money . $time . $appkey);

        $resultArr = array();

        //校验sign
        if ($sign == $sign_check) {

            $status = STATUS_SUCCESS;
            //更新订单状态
            if (false == $orderLog->recordOrder($status, $money, $userData, "pps", $platform,$order_id)) {
                $orderLog->log("pps", "order update failed , orderid:" . $userData . " platform:" . $platform);
                $resultArr['result'] = -6;
                $resultArr['message'] = "order status update failed";
                return json_encode($resultArr);
            }
            $resultArr['result'] = 0;
            $resultArr['message'] = "success";
            return json_encode($resultArr); 
        } else {
            $orderLog->log("pps", "checked failed, order:" . $userData);
            $resultArr['result'] = -1;
            $resultArr['message'] = "Sign error";
            return json_encode($resultArr); 
        }
        $resultArr['result'] = -6;
        $resultArr['message'] = "Other errors";
        return json_encode($resultArr);
    }

}

?>